// haojk/pages/commissionWithdraw/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      credit2:0.00,
      inputWithdraw:"",
      zhifubaoNum: "",
      showView:false,
     
      cashtype:0
     
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var $that = this;
   
      wx.getStorage({
          key: 'globalset',
          success: function (res) {
            
              var cashtype = res.data.cashtype;
              if(typeof cashtype=="undefined"){
                cashtype=0;
              }
              if(cashtype==2){
                $that.setData({
                  showView: true,

                  radioValue: 2,
                });
              }else{
                  $that.setData({
                    
                      radioValue: 1,
                  });
              }
              $that.setData({
                  mincash: res.data.mincash,
                  rate:res.data.rate*100,
                  cashtype:cashtype

              })

          }
      })
      wx.getStorage({
          key: "myUserinformation",
          success: function (res) {
              $that.setData({
                  credit2: res.data.credit22
              })
          }
      });
  },
  changeInput:function(e){
     
      this.setData({
          inputWithdraw: e.detail.value 
      })
    
  },
  changeInputZhifubao: function (e) {
      this.setData({
          zhifubaoNum: e.detail.value
      })

  },
  formSubmit:function(e){
    
      var $that = this;
    

      var inputWithdraw = parseFloat($that.data.inputWithdraw);
    
      var rate = parseFloat($that.data.rate);
      var mincash = parseFloat($that.data.mincash);
      var credit2 = parseFloat($that.data.credit2);
    
     

      if ($that.data.inputWithdraw == null || $that.data.inputWithdraw == "" || $that.data.inputWithdraw == 0) {
          wx.showModal({
              title: '提示',
              content: '输入值不能为空或零',
              success: function (res) {
                  if (res.confirm) {
                     
                  } else if (res.cancel) {
                     
                  }
              }
          })
      } else if (inputWithdraw<mincash){
         
          wx.showModal({
              title: '提示',
              content: '提现金额不能少于最小提现',
              success: function (res) {
                  if (res.confirm) {
                    
                  } else if (res.cancel) {
                   
                  }
              }
          })
      } else if (inputWithdraw > credit2){
          wx.showModal({
              title: '提示',
              content: '输入值不能大于佣金',
              success: function (res) {
                  if (res.confirm) {
                   
                  } else if (res.cancel) {
                      
                  }
              }
          })
      } else if ($that.data.radioValue == 2 && $that.data.zhifubaoNum == "") {
          wx.showModal({
              title: '提示',
              content: '支付宝不能为空',
              success: function (res) {
                  if (res.confirm) {
                      
                  } else if (res.cancel) {
                     
                  }
              }
          })
      }  else if ($that.data.cashtype == 2&&$that.data.zhifubaoNum == "" ) {
          wx.showModal({
              title: '提示',
              content: '支付宝不能为空',
              success: function (res) {
                  if (res.confirm) {
                    
                  } else if (res.cancel) {
                     
                  }
              }
          })
      }  else {

          app.util.request({
              url: 'entry/wxapp/ApplyCommission',
              data: {
                  "m": 'nets_haojk',
                  "money": inputWithdraw,
                  "cashtype": $that.data.radioValue,
                  "remark": $that.data.zhifubaoNum,
                  "formId": e.detail.formId
              },
              method: 'post',
              success: function (response) {
                 
                  if(response.statusCode == 200){
                      $that.getUserInfor();

                      wx.showModal({
                          title: '提示',
                          content: '申请成功,请等待审核',
                          success: function (res) {
                              if (res.confirm) {
                                
                                  wx.reLaunch({url: "../my/index"});
                                  
                              } else if (res.cancel) {
                                 
                                  wx.reLaunch({url: "../my/index"});
                              }
                          }
                      })
                      $that.setData({
                          inputWithdraw:""
                      })
                     
                  }
              }
          });
      }

  },
  //获取会员额度信息
  getUserInfor: function () {
      var $that = this;
     
      app.util.request({
          url: 'entry/wxapp/AddMember',
          data: {
              "m": 'nets_haojk',
              // "from_uid": e.data
              "from_uid": "0"
          },
          method: 'post',
          success: function (response) {
              wx.setStorage({
                  key: "myUserinformation",
                  data: response.data.data
              });
            
              var obj = response.data.data;
              $that.setData({
                  credit1: obj.credit1,
                  credit2: obj.credit2,
                  type: obj.type
              })
          }
      });
  },
  radioChange: function (e) {
      this.setData({
          radioValue: e.detail.value,
      })
      
  },
  //是否显示支付宝输入框
  radioBox:function(e){
      var $that = this;
      if ($that.data.radioValue == 2) {
          $that.setData({
              showView: true
          })
      }else{
          $that.setData({
              showView: false
          })
      }
  },
  //全部提现
  fillAllMoney:function(){
          
           var $that = this;
          
        
           $that.setData({
               inputWithdraw:$that.data.credit2
           })
         
 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})